
import Koa from 'koa';
import route from 'koa-route';
import serve from 'koa-static';
import {resolve} from 'path';

const r = path => resolve(__dirname,path);

const app = new Koa();
const about = ctx => {
    ctx.response.type = 'html';
    ctx.response.body = '<a href="/">Index Page</a>';
};

const main = ctx => {

    ctx.response.body = r('./static');
};

//把当前目录下的static作为静态资源，可以用http://x.x.x/filename/ 访问到static目录下名为filname文件
const assetServe = serve(r('./static'));

//重定向
const redirect = ctx => {
    ctx.response.redirect('/');
};
app.use(route.get('/', main));
app.use(route.get('/about', about));
app.use(route.get('/rdt', redirect));
app.use(assetServe);

app.listen(3006);

